package com.mhz.cae.level;

import java.util.ArrayList;
import java.util.List;

import org.anddev.andengine.entity.scene.Scene;
import org.anddev.andengine.extension.physics.box2d.PhysicsWorld;

import com.mhz.cae.CausesAndEffectsActivity;
import com.mhz.cae.objects.TennisBall;
import com.mhz.cae.objects.Block;
import com.mhz.cae.objects.ItemType;
import com.mhz.cae.objects.ItemType.Type;

public class Level0 implements Level {

	private static final float BALL_START_X = 50f;
	private static final float BALL_START_Y = 50f;

	private final TennisBall mBall;

	private final List<ItemType> mAvailableItems = new ArrayList<ItemType>();

	public static Level createLevel(final PhysicsWorld physicsWorld, final Scene scene) {
		return new Level0(physicsWorld, scene);
	}

	private Level0(final PhysicsWorld physicsWorld, final Scene scene) {
		// Create the fixed world
		final Block ground = Block.createObject(0, CausesAndEffectsActivity.CAMERA_HEIGHT - 2, CausesAndEffectsActivity.CAMERA_WIDTH, 2, 0f);
		final Block roof = Block.createObject(0, 0, CausesAndEffectsActivity.CAMERA_WIDTH, 2, 0f);
		final Block left = Block.createObject(0, 0, 2, CausesAndEffectsActivity.CAMERA_HEIGHT, 0f);
		final Block right = Block.createObject(CausesAndEffectsActivity.CAMERA_WIDTH - 2, 0, 2, CausesAndEffectsActivity.CAMERA_HEIGHT, 0f);
		right.initObject(physicsWorld, scene);
		left.initObject(physicsWorld, scene);
		roof.initObject(physicsWorld, scene);
		ground.initObject(physicsWorld, scene);

		// Create physics elements
		final Block block1 = Block.createObject(25f, 200f, 200f, 2f, 25f);
		final Block block2 = Block.createObject(220f, 250f, 200f, 2f, 0f);
		block1.initObject(physicsWorld, scene);
		block2.initObject(physicsWorld, scene);

		// Add inventory elements
		mAvailableItems.add(new ItemType(Type.TRAMPOLINE, 3));
		mAvailableItems.add(new ItemType(Type.SOCCER_BALL, 2));

		// Add ball
		mBall = TennisBall.createObject(BALL_START_X, BALL_START_Y);
		mBall.initObject(physicsWorld, scene);
	}

	@Override
	public void resetLevel() {
		mBall.resetObject();
	}

	@Override
	public List<ItemType> getAvailableItems() {
		return mAvailableItems;
	}
}
